let router = require('koa-router')()
let Admin = require('../../models/Admin')

router.get('/', async (ctx) => {
  ctx.render('admin/index')
})

router.get('/changeStatus', async (ctx) => {
  //console.log(ctx.query)
  let {attr, id} = ctx.query
  await Admin.findById(id).then(async (result) => {
    if (result) {
      let status = result.status === 1 ? 0 : 1
      await Admin.findByIdAndUpdate(id, {
        status: status
      }).then(updateResult => {
        if (updateResult) {
          ctx.body = {
            success: true
          }
        } else {
          ctx.body = {
            success: false
          }
        }
      })
    }
  })

  //ctx.body = {'message': '成功'}
})

module.exports = router.routes()